home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume91
/
utilitys
/
findisk3
/
part03
< prev
Wrap
Text File
|
1991-11-20
|
49KB
|
2,554 lines
Path: news.larc.nasa.gov!amiga-request
From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
Subject: v91i201: FindDisk 3.3 - disk catalogger utility, Part03/03
Reply-To: Ross MacGregor <haley@unixg.ubc.ca>
Newsgroups: comp.sources.amiga
Message-ID: <comp.sources.amiga.v91i201@ab20.larc.nasa.gov>
References: <comp.sources.amiga.v91i199@ab20.larc.nasa.gov>
Date: 20 Nov 91 11:10:59 GMT
Approved: tadguy@uunet.UU.NET (Tad Guy)
X-Mail-Submissions-To: amiga@uunet.uu.net
X-Post-Discussions-To: comp.sys.amiga.misc
Submitted-by: Ross MacGregor <haley@unixg.ubc.ca>
Posting-number: Volume 91, Issue 201
Archive-name: utilities/finddisk-3.3/part03
#!/bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 3 (of 3)."
# Contents: fd2src/fd2.c fd3src/fd3.c
# Wrapped by tadguy@ab20 on Tue Nov 19 21:17:43 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'fd2src/fd2.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fd2src/fd2.c'\"
else
echo shar: Extracting \"'fd2src/fd2.c'\" \(21252 characters\)
sed "s/^X//" >'fd2src/fd2.c' <<'END_OF_FILE'
X
X/* FindDisk2.3
X
X Author : Ross MacGregor
X Date : 27/10/88
X Last Update : 23 Apr 91
X Comments : This is a public domain program.
X
X
X DiskList storein compacted form:
X
X below: { unskrunched } => { skrunched }
X [] is a byte of memory
X
X * compacts strings of spaces
X { [$20] [$20] [$20] [$20] [$20] } => { [SKRUNCHAR] [SKRUNOFFS 5] }
X { [$20] [$20] } => { [$20] [$20] }
X
X * the STARTSTR is compacted
X { STARTSTR } => { [STARTCHAR] }
X
X*/
X
X#include <functions.h>
X#include <string.h>
X
X#include <exec/types.h>
X#include <exec/nodes.h>
X#include <exec/lists.h>
X#include <exec/libraries.h>
X#include <exec/ports.h>
X#include <exec/interrupts.h>
X#include <exec/io.h>
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X
X
X/* lattice may want smaller strings */
X
X#define HELPTEXT1 "\nFindDisk2.3:\n\
XFD -l ; Loads DiskList to ram:\n\
XFD -s ; Saves DiskList back to disk (first doing an update)\n\
XFD -d [path] ; Saves dir listing to ram:TempDL\n\
XFD -a [path] ; Saves listing with all sub-directories included\n\
XFD -u ; Updates the DiskList with TempDL\n\
XFD -n ; Creates a new (empty) DiskList\n"
X
X#define HELPTEXT2 "FD -r diskname ; Removes directory from DiskList matching 'diskname'\n\
XFD text1 [textn] ; Lists disk dir with a line containing text1 to textn\n\
X FD text ; Case insensitive scan for text\n\
X FD !text ; Case sensitive scan for for text\n"
X
X#define HELPTEXT3 "\nEnvironment Variables: (= default setting)\n\
X DLDISK = FindDisk:Disklist (Disk storage location/name)\n\
X DLTEMP = ram:DiskList (Ram storage location/name)\n\
X DLDRIVE = df0: (Captures dir of this drive)\n\n"
X
X
X#define CP_BUFF 10000L /* Buffer size for the file copy function */
X
X
X/* This indicates the start line of a dir listing, and
X it MUST have the name of the disk on the same line. */
X
X#define STARTSTR "Directory of "
X
X
X/* Special character used to compact the spaces in DiskList */
X#define SKRUNCHAR 1
X#define SKRUNOFFS 10
X
X/* Special characters used to replace the STARTSTR */
X#define STARTCHAR 2
X
X/* Lines in the stored dir listing array */
X#define NUMLINES 25
X
X/* Max length of the lines read in */
X#define LINELEN 170L
X#define MAXBUF 169L
X
XBPTR fdl, ftmp;
XBPTR confh;
X
Xchar *tempdl="ram:TempDL";
X
Xchar *dltemp="ram:DiskList", *dldisk="FindDisk:DiskList";
Xchar *sdir_pat="df0:";
X
X#define MAXPATHLEN 80
X
Xchar *dlpath;
Xchar buffer[LINELEN];
X
X/* global main arguments */
Xint glargc;
Xchar **glargv;
X
X/* function error indicator */
Xint fcnerr;
X
Xchar *outofmem="Out of Memory Error.\n";
Xchar *cutoff=" - - (no more lines available) - -\n";
X
X/* finddisk uses this */
Xchar dirlist[NUMLINES][LINELEN];
X
X
X/*------------ dynamic structure for coping DL to memory -------------*/
X
X/* Blocks of memory for storing the disklist */
X#define BLKSIZE 4096L
X
Xstruct mem_block
X{
X char buffer[BLKSIZE+1];
X struct mem_block *next;
X};
X
Xstruct mem_block *mem_blocks, *cur_mem_block;
Xchar *mem_block_ptr;
Xint chrcount;
Xvoid init_bufblks(), free_bufblks();
Xint write_bufblks(BPTR fd);
X
X/*------------ dynamic structure for listing the volume names --------*/
X/* used in recursive do_ls call also */
X
Xstruct disk
X{
X char name[LINELEN];
X struct disk *next;
X};
Xstruct disk *firstdisk,*diskptr;
X
X#define INIT_DISKNAMES firstdisk=diskptr=NULL
X#define FREE_DISKNAMES free_disknames()
X
Xvoid free_disknames();
X
X/*----------------------------------------------------------------------*/
X
Xchar *mystrstr(), *strtoupper(), *getstr();
Xvoid putstr();
X
Xchar *skrunch(), *getenv();
Xvoid unskrunch(), get_dlpath();
X
XBPTR opendl(), opentmp();
Xchar *getenv();
Xvoid get_dlpath();
X
Xvoid finddisk();
Xvoid print_dir_if(int thisone,int line);
X
Xint update(), remove(), loaddl(), savedl(), sdir(), newdl();
X
Xvoid update_free(), ls_free(), remove_free();
X
Xchar *strchr(), *malloc();
X
Xvoid main(argc,argv)
X int argc;
X char *argv[];
X{
X
X glargv=argv;
X glargc=argc;
X
X if( (confh=Output())==NULL )
X exit(1);
X
X if( argc==1)
X {
X putstr(HELPTEXT1);
X putstr(HELPTEXT2);
X putstr(HELPTEXT3);
X exit(0);
X }
X
X dldisk=getenv("env:dldisk",dldisk);
X dltemp=getenv("env:dltemp",dltemp);
X sdir_pat=getenv("env:dldrive",sdir_pat);
X get_dlpath();
X
X if( *argv[1]=='-' )
X {
X switch( *(argv[1]+1) )
X {
X case 'd': if( sdir(0) )
X putstr("SaveDir failed!\n");
X break;
X
X case 'a': if( sdir(1) )
X putstr("SaveDir failed!\n");
X break;
X
X case 's': if( savedl() )
X putstr("SaveDL failed!\n");
X break;
X
X case 'l': if( loaddl() )
X putstr("LoadDL failed!\n");
X break;
X
X case 'u': if( update() )
X putstr("Update failed!\n");
X break;
X
X case 'r': if( remove() )
X putstr("Remove failed!\n");
X break;
X
X case 'n': if( newdl() )
X putstr("Empty DiskList created (Save if in RAM).\n");
X break;
X
X default : putstr("Unknown Option.\n");
X }
X }
X else finddisk();
X
X}
X
X
Xchar *getenv(fullpath,var)
X char *fullpath, *var;
X{
X BPTR lock;
X BPTR fh;
X char *buffer;
X int len;
X
X if( lock=Lock(fullpath,(long)ACCESS_READ) )
X {
X UnLock(lock);
X if( !(fh=Open(fullpath,(long)MODE_OLDFILE)) )
X return var;
X if( !(buffer=(char *)malloc(MAXPATHLEN+1)) )
X {
X putstr(outofmem);
X Close(fh);
X return var;
X }
X len=Read(fh,buffer,(long)MAXPATHLEN);
X Close(fh);
X *(buffer+len)='\0';
X return buffer;
X }
X return var;
X}
X
X
Xvoid finddisk()
X{
X int kase=0, thisone=0, line=0;
X int i;
X char *p;
X
X if( !(fdl=opendl((long)MODE_OLDFILE)) )
X return;
X
X /* Converts non-case sensitive keywords to upper case */
X for(i=1; i<glargc; i++)
X if( *glargv[i]!='!' )
X strtoupper(glargv[i]);
X
X /* get line of DiskList */
X while( getstr(buffer,fdl) !=NULL )
X {
X
X /* first checks for a startchar of a dirlist */
X if( strchr(buffer,(char)STARTCHAR) )
X {
X print_dir_if(thisone,line);
X thisone=0;
X line=1;
X }
X
X if( line )
X {
X /* Copies the line in buffer to the stored dirlist */
X strcpy(dirlist[line-1],buffer);
X
X if( ++line > NUMLINES )
X line--;
X
X /* Checks for given keywords */
X if( thisone==0 )
X for(i=1; i<glargc; i++)
X {
X if( *glargv[i]=='!' )
X {
X p=glargv[i]+1;
X kase=1;
X }
X else
X {
X p=glargv[i];
X kase=0;
X }
X
X if( mystrstr(buffer,p,kase) )
X thisone=1;
X else
X {
X thisone=0;
X break;
X }
X }
X
X }/* if(line) */
X
X } /* while( get next buffer) */
X
X print_dir_if(thisone,line);
X
X Close(fdl);
X}
X
Xvoid print_dir_if(int thisone,int line)
X{
X int i;
X
X if( thisone )
X {
X line--;
X for(i=0; i<line; i++)
X unskrunch(dirlist[i]);
X
X /* if at the end of the dirlist array- prints 'cut off' */
X if( line==NUMLINES-1 )
X putstr(cutoff);
X }
X}
X
X
X
X#define update_cleanup(x) { update_free(); return x; }
X
Xupdate()
X{
X int i;
X
X if( !(fdl=opendl((long)MODE_OLDFILE)) )
X return 1;
X
X if( !(ftmp=opentmp((long)MODE_OLDFILE)) )
X {
X Close(fdl);
X return 0;
X }
X
X INIT_DISKNAMES;
X init_bufblks();
X
X /* finds the disks names in TempDL */
X while( getstr(buffer,ftmp) !=NULL )
X {
X if( mystrstr(buffer,STARTSTR,1) )
X {
X skrunch(buffer);
X if( storename(buffer) )
X update_cleanup(3)
X }
X }
X if( fcnerr )
X update_cleanup(10)
X
X if( storedl() )
X update_cleanup(4)
X
X Seek(ftmp,0L,(long)OFFSET_BEGINNING);
X
X /* store TempDL in memory */
X while( getstr(buffer,ftmp) !=NULL )
X if( store( skrunch(buffer) ) )
X update_cleanup(5)
X if( fcnerr )
X update_cleanup(6);
X
X Close(fdl);
X if( !(fdl=opendl((long)MODE_NEWFILE)) )
X {
X Close(ftmp);
X FREE_DISKNAMES;
X free_bufblks();
X return 7;
X }
X
X /* write the in memory disklist to the one in ram: */
X if( write_bufblks(fdl) )
X update_cleanup(8)
X
X Close(ftmp);
X if( !(ftmp=opentmp((long)MODE_NEWFILE)) )
X update_cleanup(9)
X
X update_free();
X return 0;
X}
X
Xvoid update_free()
X{
X Close(fdl);
X Close(ftmp);
X FREE_DISKNAMES;
X free_bufblks();
X}
X
X
X
X
X#define remove_cleanup(x) { remove_free(); return x; }
X
Xremove()
X{
X int i;
X
X if( !(fdl=opendl((long)MODE_OLDFILE)) )
X return 2;
X
X INIT_DISKNAMES;
X init_bufblks();
X
X /* finds the disk name in DiskList */
X while( getstr(buffer,fdl) !=NULL )
X {
X if( mystrstr(buffer,glargv[2],1) )
X {
X if( storename(buffer) )
X remove_cleanup(3)
X }
X }
X if( fcnerr )
X remove_cleanup(4);
X
X Seek(fdl,0L,(long)OFFSET_BEGINNING);
X
X if( storedl() )
X remove_cleanup(5)
X
X Close(fdl);
X if( !(fdl=opendl((long)MODE_NEWFILE)) )
X {
X FREE_DISKNAMES;
X free_bufblks();
X return 6;
X }
X
X /* write the in memory disklist to the one in ram: */
X if( write_bufblks(fdl) )
X remove_cleanup(7)
X
X remove_free();
X return 0;
X}
X
X
Xvoid remove_free()
X{
X Close(fdl);
X FREE_DISKNAMES;
X free_bufblks();
X}
X
X
X
X/* loads the DiskList into memory but leaves out the directories in the
X diskname list, pointed to by firstdisk */
Xstoredl()
X{
X int storeit=1; /* saving this directory */
X
X /* doesn't store directories that are in the temp file */
X while( getstr(buffer,fdl) !=NULL )
X {
X if( strchr(buffer,(char)STARTCHAR) )
X {
X storeit=1;
X diskptr=firstdisk;
X while(diskptr)
X {
X if( mystrstr(buffer,diskptr->name,1) )
X {
X storeit=0;
X break;
X }
X diskptr=diskptr->next;
X }
X }
X
X if(storeit)
X if( store(buffer) )
X return 1;
X }
X
X return fcnerr;
X}
X
X
X
X/* Saves the name of a disk in a linked list structure */
Xstorename(buffer)
X char *buffer;
X{
X if( diskptr==NULL )
X {
X if( (firstdisk=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
X {
X putstr(outofmem);
X return 1;
X }
X diskptr=firstdisk;
X strcpy(diskptr->name,buffer);
X diskptr->next=NULL;
X }
X else
X {
X if( (diskptr->next=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
X {
X putstr(outofmem);
X return 2;
X }
X diskptr=diskptr->next;
X strcpy(diskptr->name,buffer);
X diskptr->next=NULL;
X }
X
X return 0;
X}
X
Xvoid free_disknames()
X{
X struct disk *p;
X
X while(firstdisk)
X {
X p=firstdisk->next;
X free(firstdisk);
X firstdisk=p;
X }
X}
X
X
X/* prints line to stdout unskrunched */
X/* format [BYTE]=> [SKRUNCHAR] [# of spaces ] */
X
Xvoid unskrunch(line)
X char *line;
X{
X char output[LINELEN], *p;
X int i;
X
X p=output;
X while(*line)
X {
X switch((int)*line)
X {
X case SKRUNCHAR : line++;
X for(i=SKRUNOFFS; i<(int)*line; i++)
X *(p++)=' ';
X break;
X
X case STARTCHAR : strcpy(p,STARTSTR);
X p+=strlen(STARTSTR);
X break;
X
X default : *(p++)=*line;
X }
X
X line++;
X }
X *p='\0';
X putstr(output);
X}
X
X
Xchar *skrunch(line)
X char *line;
X{
X char skbuf[LINELEN],*p;
X int spaces=0;
X
X /* first tokenizes the STARTSTR/XnSTR if in line */
X
X tokenize(line,STARTSTR,STARTCHAR);
X
X /* this is the compaction of >2 spaces */
X p=skbuf;
X while( *line )
X {
X if( *line==' ' )
X spaces++;
X else
X {
X if( spaces )
X if( spaces>2 )
X {
X *(p++)=(char)SKRUNCHAR;
X *(p++)=(char)(spaces+SKRUNOFFS);
X spaces=0;
X }
X else
X {
X *(p++)=' ';
X if( spaces>1 ) *(p++)=' ';
X spaces=0;
X }
X
X *p=*line;
X p++;
X }
X line++;
X }
X *p='\0';
X strcpy(buffer,skbuf);
X return buffer;
X}
X
X
X/* will tokenize first occurance of STR in LINE */
Xtokenize(line,str,chr)
X char *line,*str;
X int chr;
X{
X char *p,*q;
X
X if( p=mystrstr(line,str,1) )
X {
X q=p+strlen(str);
X *p=(char)chr;
X strcpy(p+1,q);
X return 1;
X }
X return 0;
X}
X
X
X
X/* stores line to memory */
Xstore(buffer)
X char *buffer;
X{
X struct mem_block *p;
X int i;
X
X i=strlen(buffer);
X chrcount+=i;
X
X if( chrcount>=BLKSIZE )
X {
X if( mem_block_ptr )
X *mem_block_ptr='\0';
X chrcount=i;
X
X if( (p=(struct mem_block *)malloc(sizeof(struct mem_block)) )==NULL)
X {
X putstr(outofmem);
X return 2;
X }
X
X p->next=NULL;
X
X if( mem_blocks )
X cur_mem_block->next=p;
X else
X mem_blocks=p;
X cur_mem_block=p;
X
X mem_block_ptr=cur_mem_block->buffer;
X }
X
X strcpy(mem_block_ptr,buffer);
X mem_block_ptr+=i;
X
X return 0;
X}
X
Xwrite_bufblks(BPTR fd)
X{
X struct mem_block *p;
X
X p=mem_blocks;
X while(p)
X {
X if( fputstr(p->buffer,fd) )
X return 1;
X p=p->next;
X }
X
X return 0;
X}
X
X
Xvoid init_bufblks()
X{
X mem_block_ptr=NULL;
X chrcount=BLKSIZE+1;
X cur_mem_block=NULL;
X mem_blocks=NULL;
X}
X
Xvoid free_bufblks()
X{
X struct mem_block *p,*next;
X
X p=mem_blocks;
X while(p)
X {
X next=p->next;
X free(p);
X p=next;
X }
X}
X
X
X/* OK, this is not quite a true strstr() with case switch.
X The sub string must be in upper case if kase=0 (?!sorry) */
X
Xchar *mystrstr(str,sub,kase)
X char *str,*sub;
X int kase;
X{
X int length;
X
X length=strlen(sub);
X
X if( kase )
X str=strchr(str,*sub);
X else
X str=strchr(strtoupper(str),*sub);
X
X while( str )
X {
X if( strncmp(str,sub,length) )
X str++;
X else
X return str;
X
X str=strchr(str,*sub);
X }
X
X return NULL;
X}
X
Xchar *strtoupper(s)
X char *s;
X{
X register char *p = s;
X
X while(*p)
X {
X *p = toupper(*p);
X p++;
X }
X return(s);
X}
X
Xvoid get_dlpath()
X{
X BPTR lock;
X
X if( lock=Lock(dltemp,(long)ACCESS_READ) )
X {
X dlpath=dltemp;
X UnLock(lock);
X }
X else
X dlpath=dldisk;
X}
X
XBPTR opendl(mode)
X long mode;
X{
X BPTR fdl;
X
X if( (fdl=Open(dlpath,mode))==NULL)
X {
X putstr("Error: Could not open DiskList\n");
X return 0;
X }
X return fdl;
X}
X
X
X#define MODE_APPEND 1000L
X
XBPTR opentmp(mode)
X long mode;
X{
X BPTR ftmp;
X BPTR lock;
X int seek=0;
X
X if( mode==MODE_APPEND)
X {
X if( lock=Lock(tempdl,(long)ACCESS_READ) )
X {
X UnLock(lock);
X mode=(long)MODE_OLDFILE;
X seek=1;
X }
X else
X mode=(long)MODE_NEWFILE;
X }
X
X if( (ftmp=Open(tempdl,mode))==NULL)
X {
X putstr("Error: Could not open RAM:TempDL\n");
X return 0;
X }
X
X if( seek )
X Seek(ftmp,0L,(long)OFFSET_END);
X
X return ftmp;
X}
X
X
Xsdir(recur)
X int recur;
X{
X char *p;
X
X
X if( glargc>2 )
X p=glargv[2];
X else
X p=sdir_pat;
X
X if( !(ftmp=opentmp(MODE_APPEND)) )
X return 1;
X
X if( do_ls(p,ftmp,recur) )
X {
X Close(ftmp);
X return 2;
X }
X Close(ftmp);
X return 0;
X}
X
X
X#define ls_cleanup(x) { ls_free(lock,f_info); return x; }
X
Xdo_ls(pat,fh,recur)
X char *pat;
X BPTR fh;
X int recur;
X{
X BPTR lock=NULL;
X struct FileInfoBlock *f_info;
X
X char *s, *tempstr;
X int slen, isadir, col, patchg=0, firstrun=1;
X char *spaces1, *spaces2;
X struct disk *nextdir;
X char basename[80], tempname[80];
X
X
X /* strings of 18 & 36 spaces for formatting output */
X /* 012345678901234567 */
X spaces1=" ";
X /* 0123456789012345678901234567890123456 */
X spaces2=" ";
X
X INIT_DISKNAMES;
X nextdir=NULL;
X
X strcpy(tempname,"/");
X tempstr=tempname+1;
X
X if((f_info=(struct FileInfoBlock *)
X AllocMem((long)sizeof(struct FileInfoBlock),0L))==0)
X {
X putstr(outofmem);
X FREE_DISKNAMES;
X return 1;
X }
X
X do
X {
X if( firstdisk )
X {
X while( nextdir && *(nextdir->name)=='/' )
X {
X strncpy(basename,(nextdir->name)+1,78);
X strncpy(basename+strlen(basename),"/",2);
X nextdir=nextdir->next;
X if( !nextdir )
X ls_cleanup(0)
X }
X strncpy(tempname+1,basename,78);
X slen=strlen(tempname);
X strncpy(tempname+slen,nextdir->name,79-slen);
X if( storename(tempname) )
X ls_cleanup(1);
X pat=tempname+1;
X }
X
X do
X {
X if( firstrun )
X {
X if(patchg==1)
X {
X patchg=2;
X strncpy(tempstr,f_info->fib_FileName,78);
X slen=strlen(tempstr);
X tempstr[slen]=':';
X strncpy(tempstr+slen+1,s+4,78-slen);
X pat=tempstr;
X }
X else if( strchr(pat,':')<strchr(pat,'\0')-1 )
X {
X patchg=2;
X if( !(strncmp(pat,"df0:",4) && strncmp(pat,"df1:",4)) )
X {
X patchg=1;
X strncpy(tempstr,pat,4);
X *(tempstr+4)='\0';
X s=pat;
X pat=tempstr;
X }
X }
X }
X
X if((lock=Lock(pat,(long)ACCESS_READ))==0)
X ls_cleanup(2)
X
X if((Examine(lock,f_info))==0)
X ls_cleanup(3)
X }
X while( patchg==1 );
X firstrun=0;
X
X if( fputstr(STARTSTR,fh) )
X ls_cleanup(4)
X if( firstdisk )
X {
X fputstr(tempname+1,fh);
X fputstr ("\n",fh);
X }
X else
X {
X if( patchg )
X {
X patchg=0;
X if( fputstr(pat,fh) )
X ls_cleanup(5)
X fputstr ("\n",fh);
X strncpy(basename,pat,79L);
X slen=strlen(basename);
X basename[slen++]='/';
X basename[slen]='\0';
X
X }
X else
X {
X if( fputstr(f_info->fib_FileName,fh) )
X ls_cleanup(6)
X fputstr (":\n",fh);
X strncpy(basename,f_info->fib_FileName,78);
X slen=strlen(basename);
X basename[slen++]=':';
X basename[slen]='\0';
X }
X }
X col=0;
X
X while( (ExNext(lock,f_info))!=0)
X {
X s=f_info->fib_FileName;
X slen=strlen(s);
X isadir= (f_info->fib_DirEntryType>0);
X
X if((col == 3) && slen >18) {
X fputstr("\n",fh);
X col = 0;
X }
X
X if (isadir)
X fputstr ("\033[33m ",fh);
X else
X fputstr (" ",fh);
X
X if (slen >18) {
X if( fputstr(s,fh) )
X ls_cleanup(7)
X col += 2;
X if( fputstr(spaces2+slen,fh) )
X ls_cleanup(8)
X }
X else {
X if( fputstr(s,fh) )
X ls_cleanup(9)
X if( fputstr(spaces1+slen,fh) )
X ls_cleanup(10)
X col++;
X }
X
X if( isadir && recur )
X if(storename(s))
X ls_cleanup(1);
X
X if (isadir)
X fputstr("\033[0m",fh);
X
X if (col > 3) {
X fputstr("\n",fh);
X col = 0;
X }
X
X }
X fputstr("\n",fh);
X if( col )
X fputstr("\n",fh);
X
X UnLock(lock);
X lock=NULL;
X
X if( nextdir )
X nextdir=nextdir->next;
X else
X nextdir=firstdisk;
X }
X while( nextdir );
X
X ls_free(lock,f_info);
X return 0;
X}
X
Xvoid ls_free(lock,f_info)
X BPTR lock;
X struct FileInfoBlock *f_info;
X
X{
X if( lock )
X UnLock(lock);
X FreeMem(f_info,(long)sizeof(struct FileInfoBlock));
X FREE_DISKNAMES;
X}
X
Xvoid putstr(str)
X char *str;
X{
X Write(confh,str,(long)strlen(str));
X}
X
X
Xfputstr(str,fh)
X char *str;
X BPTR fh;
X{
X long len;
X len=(long)strlen(str);
X if( Write(fh,str,len)==len)
X return 0;
X return 1;
X}
X
X/* must be used in the WHILE( GETSTR()!=NULL) fashion */
Xchar *getstr(line,f)
X char *line;
X BPTR f;
X{
X static char *buffer, *bufptr;
X static int last_read;
X int len, n=MAXBUF;
X char temp, *p, empty='\0';
X
X if( !buffer )
X {
X if( (buffer=(char *)AllocMem((long)CP_BUFF+1,0L))==0)
X {
X putstr(outofmem);
X fcnerr=1;
X return (char *)0;
X }
X bufptr=∅
X }
X
X while(1)
X if( p=strchr(bufptr,'\n') )
X {
X temp=*(++p);
X *p='\0';
X strncpy(line,bufptr,n);
X *p=temp;
X bufptr=p;
X return line;
X }
X else
X {
X strncpy(line,bufptr,n);
X len=strlen(line);
X n-=len;
X line+=len;
X
X if( last_read )
X {
X FreeMem(buffer,CP_BUFF+1);
X buffer=0;
X last_read=0;
X return (char *)0;
X }
X else
X if( (len=Read(f,buffer,CP_BUFF)) <1 )
X last_read=1;
X else
X {
X last_read= len!=CP_BUFF;
X bufptr=buffer;
X *(buffer+len)='\0';
X }
X }
X}
X
Xsavedl()
X{
X if( update() )
X return 1;
X
X if( strcmp(dlpath,dldisk) )
X {
X if( copy(dlpath,dldisk) )
X return 1;
X DeleteFile(dlpath);
X DeleteFile(tempdl);
X }
X return 0;
X}
X
Xloaddl()
X{
X if( strcmp(dltemp,dlpath) )
X if( copy(dlpath,dltemp) )
X return 1;
X return 0;
X}
X
Xnewdl()
X{
X BPTR fh;
X
X putstr("Are you sure? ");
X Read(confh,buffer,LINELEN);
X
X if( *buffer=='y' )
X {
X if( fh=Open(dlpath,(long)MODE_NEWFILE) )
X {
X Close(fh);
X return 0;
X }
X return 1;
X }
X return 0;
X}
X
Xcopy(src,dest)
X char *src,*dest;
X{
X BPTR sfh,dfh;
X char *buffer;
X int len;
X
X if((sfh=Open(src,(long)MODE_OLDFILE))==0)
X return 1;
X
X if((dfh=Open(dest,(long)MODE_NEWFILE))==0)
X {
X Close(sfh);
X return 2;
X }
X if( (buffer=(char *)AllocMem(CP_BUFF,0L))==0)
X {
X Close(sfh);
X Close(dfh);
X putstr(outofmem);
X return 3;
X }
X
X do
X {
X len=Read(sfh,buffer,CP_BUFF);
X Write(dfh,buffer,(long)len);
X }
X while( len!=0 );
X
X FreeMem(buffer,CP_BUFF);
X
X Close(sfh);
X Close(dfh);
X return 0;
X}
X
X
X
X
END_OF_FILE
if test 21252 -ne `wc -c <'fd2src/fd2.c'`; then
echo shar: \"'fd2src/fd2.c'\" unpacked with wrong size!
fi
# end of 'fd2src/fd2.c'
fi
if test -f 'fd3src/fd3.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'fd3src/fd3.c'\"
else
echo shar: Extracting \"'fd3src/fd3.c'\" \(22393 characters\)
sed "s/^X//" >'fd3src/fd3.c' <<'END_OF_FILE'
X
X/* FindDisk3.3
X
X Author : Ross MacGregor
X Date : 10/04/88
X Last Update : 23 Apr 91
X Comments : This is a public domain program.
X
X
X DiskList stored in compacted form:
X
X below: { unskrunched } => { skrunched }
X [] is a byte of memory
X
X * compacts strings of spaces
X { [$20] [$20] [$20] [$20] [$20] } => { [SKRUNCHAR] [SKRUNOFFS 5] }
X { [$20] [$20] } => { [$20] [$20] }
X
X * the STARTSTR is compacted
X { STARTSTR } => { [STARTCHAR] }
X
X*/
X
X#include <functions.h>
X#include <string.h>
X
X#include <exec/types.h>
X#include <exec/nodes.h>
X#include <exec/lists.h>
X#include <exec/libraries.h>
X#include <exec/ports.h>
X#include <exec/interrupts.h>
X#include <exec/io.h>
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include <libraries/filehandler.h>
X
X
X#define DISP_LINES 23
X
X#define CP_BUFF 10000L /* Buffer size for the file copy function */
X
X/* This indicates the start line of a dir listing, and
X it MUST have the name of the disk on the same line. */
X
X#define STARTSTR "Directory of "
X
X/* Special character used to compact the spaces in DiskList */
X#define SKRUNCHAR 1
X#define SKRUNOFFS 10
X
X/* Special characters used to replace the STARTSTR & XnSTR in DiskList */
X#define STARTCHAR 2
X
X/* Lines in the stored dir listing array */
X#define NUMLINES 25
X
X/* Max length of the lines read in */
X#define LINELEN 170L
X#define MAXBUF 169L
X
X#define MAXPATHLEN 80
X
X/*--------------------- Global Variables ------------------------*/
X
XBPTR fdl, ftmp;
XBPTR confh;
X
Xchar *tempdl="ram:TempDL";
X
Xchar *dltemp="ram:DiskList";
Xchar *dldisk="FindDisk:DiskList";
Xchar *sdir_pat="df0:";
X
Xchar *outofmem="Out of Memory.";
Xchar *cutoff=" - - (no more lines available) - - \n";
X
Xchar dlpath[MAXPATHLEN+1];
Xchar buffer[LINELEN];
X
X/* finddisk uses this */
Xchar dirlist[NUMLINES][LINELEN];
X
Xint con_print_line, last_startchar, disp_list;
Xchar *errorstr;
Xchar *nullstr="";
X
X/* function error indicator */
Xint fcnerr;
X
X/* global main arguments */
Xint glargc;
Xchar **glargv;
X
Xextern char strbuf[];
Xextern int subdir, shdsp;
X
X/*------------ dynamic structure for coping DL to memory -------------*/
X
X/* Blocks of memory for storing the disklist */
X#define BLKSIZE 4096L
X
Xstruct mem_block
X{
X char buffer[BLKSIZE+1];
X struct mem_block *next;
X};
X
Xstruct mem_block *mem_blocks, *cur_mem_block;
Xchar *mem_block_ptr;
Xint chrcount;
Xvoid init_bufblks(), free_bufblks();
Xint write_bufblks(BPTR fd);
X
X/*------------ dynamic structure for listing the volume names --------*/
X/* used in recursive do_ls call also */
X
Xstruct disk
X{
X char name[LINELEN];
X struct disk *next;
X};
Xstruct disk *firstdisk,*diskptr;
X
X#define INIT_DISKNAMES firstdisk=diskptr=NULL
X#define FREE_DISKNAMES free_disknames()
X
Xvoid free_disknames();
X
X/*----------------------------------------------------------------------*/
X
Xchar *mystrstr(), *strtoupper(), *getstr();
X
Xchar *skrunch(), *getenv(), *firstchar();
Xvoid tocon(), unskrunch(), get_dlpath();
XBPTR opendl(), opentmp();
X
Xchar *strchr(), *malloc();
X
Xint update(), remove(), loaddl(), savedl(), sdir(), newdl();
X
Xvoid finddisk_free(), update_free(), remove_free(), ls_free();
X
Xchar *getenv(fullpath,var)
X char *fullpath, *var;
X{
X BPTR lock;
X BPTR fh;
X char *buffer;
X int len;
X
X if( lock=Lock(fullpath,(long)ACCESS_READ) )
X {
X UnLock(lock);
X if( !(fh=Open(fullpath,(long)MODE_OLDFILE)) )
X return var;
X if( !(buffer=(char *)malloc(MAXPATHLEN+1)) )
X {
X errorstr=outofmem;
X Close(fh);
X return var;
X }
X len=Read(fh,buffer,(long)MAXPATHLEN);
X Close(fh);
X *(buffer+len)='\0';
X return buffer;
X }
X return var;
X}
X
Xtmpsize()
X{
X int size;
X if( !(ftmp=opentmp((long)MODE_OLDFILE)) )
X {
X errorstr=nullstr;
X return 0;
X }
X size=Read(ftmp,buffer,(long)MAXBUF);
X Close(ftmp);
X return size;
X}
X
X#define finddisk_cleanup(x) { finddisk_free(); return x; }
Xfinddisk()
X{
X int thisone=0, line=0;
X int i;
X
X if( !(fdl=opendl((long)MODE_OLDFILE)) )
X return 1;
X
X confh=0;
X
X /* Converts non-case sensitive keywords to upper case */
X for(i=1; i<glargc; i++)
X if( *glargv[i]!='!' )
X strtoupper(glargv[i]);
X
X con_print_line=0;
X disp_list=1;
X
X /* get line of DiskList */
X while( getstr(buffer,fdl)!=NULL && disp_list)
X {
X /* first checks for a startchar of a dirlist */
X if( strchr(buffer,(char)STARTCHAR) )
X {
X if( thisone )
X {
X last_startchar=con_print_line;
X if( printdir(&line) )
X finddisk_cleanup(1);
X thisone=0;
X }
X
X line=1;
X }
X
X
X if( line )
X {
X
X /* Copies the line in buffer to the stored dirlist */
X strcpy(dirlist[line-1],buffer);
X
X if( ++line > NUMLINES )
X line--;
X
X /* Checks for given keywords */
X if( thisone==0 )
X thisone=chkmatch(buffer);
X }/* if(line) */
X
X } /* while( get next buffer) */
X if( fcnerr )
X {
X fcnerr=0;
X finddisk_cleanup(2);
X }
X
X if( !disp_list )
X while( getstr(buffer,fdl)!=NULL);
X else
X {
X if( thisone )
X if( printdir(&line) )
X finddisk_cleanup(3);
X
X if( con_print_line )
X {
X fputstr("[ Quit ]",confh);
X Read(confh,buffer,5L);
X }
X }
X
X finddisk_cleanup(0)
X}
X
Xvoid finddisk_free()
X{
X Close(fdl);
X if( confh )
X Close(confh);
X}
X
X
Xprintdir(line)
X int *line;
X{
X int i;
X
X if( !confh )
X if( (confh=Open("CON:0/0/640/200/FindDisk3.3",(long)MODE_OLDFILE))==0)
X {
X errorstr=(" Could not open display window.");
X return 1;
X }
X
X /* print the directory */
X (*line)--;
X for(i=0; i<*line; i++)
X if( shdsp && i )
X {
X if( chkmatch(dirlist[i]) )
X unskrunch(dirlist[i]);
X }
X else
X unskrunch(dirlist[i]);
X
X /* if at the end of the dirlist array- prints 'cut off' */
X if( *line==NUMLINES-1 )
X tocon(cutoff);
X
X return 0;
X}
X
X
Xchkmatch(buffer)
X char *buffer;
X{
X int i, kase;
X char *p;
X
X for(i=1; i<glargc; i++)
X {
X if( *glargv[i]=='!' )
X {
X p=glargv[i]+1;
X kase=1;
X }
X else
X {
X p=glargv[i];
X kase=0;
X }
X if( !mystrstr(buffer,p,kase) )
X return 0;
X }
X return 1;
X}
X
X
Xvoid tocon(s)
X char *s;
X{
X char inp[6];
X
X if( ++con_print_line>=DISP_LINES )
X {
X fputstr("[ More... ]",confh);
X Read(confh,inp,5L);
X inp[5]='\0';
X if( strchr(inp,'q') )
X disp_list=0;
X fputstr("\013\033[K\015",confh);
X con_print_line-=last_startchar;
X }
X fputstr(s,confh);
X}
X
X
X#define update_cleanup(x) { update_free(); return x; }
X
Xupdate()
X{
X int i;
X
X if( !(fdl=opendl((long)MODE_OLDFILE)) )
X return 1;
X
X if( !(ftmp=opentmp((long)MODE_OLDFILE)) )
X {
X Close(fdl);
X return 0;
X }
X
X INIT_DISKNAMES;
X init_bufblks();
X
X /* finds the disks names in TempDL */
X while( getstr(buffer,ftmp) !=NULL )
X {
X if( mystrstr(buffer,STARTSTR,1) )
X {
X skrunch(buffer);
X if( storename(buffer) )
X update_cleanup(3)
X }
X }
X if( fcnerr )
X {
X fcnerr=0;
X update_cleanup(10)
X }
X
X if( storedl() )
X update_cleanup(4)
X
X Seek(ftmp,0L,(long)OFFSET_BEGINNING);
X
X /* store TempDL in memory */
X while( getstr(buffer,ftmp) !=NULL )
X if( store( skrunch(buffer) ) )
X update_cleanup(5)
X if( fcnerr )
X {
X fcnerr=0;
X update_cleanup(6);
X }
X
X Close(fdl);
X if( !(fdl=opendl((long)MODE_NEWFILE)) )
X {
X Close(ftmp);
X FREE_DISKNAMES;
X free_bufblks();
X return 6;
X }
X
X /* write the in memory disklist to the one in ram: */
X if( write_bufblks(fdl) )
X update_cleanup(8)
X
X Close(ftmp);
X if( !(ftmp=opentmp((long)MODE_NEWFILE)) )
X update_cleanup(7)
X
X update_free();
X return 0;
X}
X
Xvoid update_free()
X{
X Close(fdl);
X Close(ftmp);
X FREE_DISKNAMES;
X free_bufblks();
X}
X
X
X#define remove_cleanup(x) { remove_free(); return x; }
X
Xremove()
X{
X int i;
X char *p;
X
X if( *(p=firstchar(strbuf))=='\0' )
X return 1;
X
X if( !(fdl=opendl((long)MODE_OLDFILE)) )
X return 2;
X
X INIT_DISKNAMES;
X init_bufblks();
X
X /* finds the disk name in DiskList */
X while( getstr(buffer,fdl) !=NULL )
X {
X if( mystrstr(buffer,p,1) )
X {
X if( storename(buffer) )
X remove_cleanup(3)
X }
X }
X if( fcnerr )
X {
X fcnerr=0;
X remove_cleanup(4);
X }
X
X Seek(fdl,0L,(long)OFFSET_BEGINNING);
X
X if( storedl() )
X remove_cleanup(4)
X
X Close(fdl);
X if( !(fdl=opendl((long)MODE_NEWFILE)) )
X {
X FREE_DISKNAMES;
X free_bufblks();
X return 5;
X }
X
X /* write the in memory disklist to the one in ram: */
X if( write_bufblks(fdl) )
X remove_cleanup(6)
X
X remove_free();
X return 0;
X}
X
Xvoid remove_free()
X{
X Close(fdl);
X FREE_DISKNAMES;
X free_bufblks();
X}
X
X
X/* loads the DiskList into memory but leaves out the directories in the
X diskname list, pointed to by firstdisk */
Xstoredl()
X{
X int storeit=1; /* saving this directory */
X
X /* doesn't store directories that are in the temp file */
X while( getstr(buffer,fdl) !=NULL )
X {
X if( strchr(buffer,(char)STARTCHAR) )
X {
X storeit=1;
X diskptr=firstdisk;
X while(diskptr)
X {
X if( mystrstr(buffer,diskptr->name,1) )
X {
X storeit=0;
X break;
X }
X diskptr=diskptr->next;
X }
X }
X
X if(storeit)
X if( store(buffer) )
X return 1;
X }
X
X if( fcnerr )
X {
X fcnerr=0;
X return 2;
X }
X return 0;
X}
X
X/* must be used in the WHILE( GETSTR()!=NULL) fashion */
Xchar *getstr(line,f)
X char *line;
X BPTR f;
X{
X static char *buffer, *bufptr;
X static int last_read;
X int len, n=MAXBUF;
X char temp, *p, empty='\0';
X
X if( !buffer )
X {
X if( (buffer=(char *)AllocMem((long)CP_BUFF+1,0L))==0)
X {
X errorstr=outofmem;
X fcnerr=1;
X return (char *)0;
X }
X bufptr=∅
X }
X
X while(1)
X if( p=strchr(bufptr,'\n') )
X {
X temp=*(++p);
X *p='\0';
X strncpy(line,bufptr,n);
X *p=temp;
X bufptr=p;
X return line;
X }
X else
X {
X strncpy(line,bufptr,n);
X len=strlen(line);
X n-=len;
X line+=len;
X
X if( last_read )
X {
X FreeMem(buffer,CP_BUFF+1);
X buffer=0;
X last_read=0;
X return (char *)0;
X }
X else
X if( (len=Read(f,buffer,CP_BUFF)) <1 )
X last_read=1;
X else
X {
X last_read= len!=CP_BUFF;
X bufptr=buffer;
X *(buffer+len)='\0';
X }
X }
X}
X
X
X/* Saves the name of a disk in a linked list structure */
Xstorename(buffer)
X char *buffer;
X{
X if( diskptr==NULL )
X {
X if( (firstdisk=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
X {
X errorstr=outofmem;
X return 1;
X }
X diskptr=firstdisk;
X strcpy(diskptr->name,buffer);
X diskptr->next=NULL;
X }
X else
X {
X if( (diskptr->next=(struct disk *)malloc(sizeof(struct disk)) )==NULL)
X {
X errorstr=outofmem;
X return 2;
X }
X diskptr=diskptr->next;
X strcpy(diskptr->name,buffer);
X diskptr->next=NULL;
X }
X
X return 0;
X}
X
Xvoid free_disknames()
X{
X struct disk *p;
X
X while(firstdisk)
X {
X p=firstdisk->next;
X free(firstdisk);
X firstdisk=p;
X }
X}
X
X
X/* prints line to confh unskrunched */
X/* format [BYTE]=> [SKRUNCHAR] [# of spaces ] */
X
Xvoid unskrunch(line)
X char *line;
X{
X char output[LINELEN], *p;
X int i;
X
X p=output;
X while(*line)
X {
X switch((int)*line)
X {
X case SKRUNCHAR : line++;
X for(i=SKRUNOFFS; i<(int)*line; i++)
X *(p++)=' ';
X break;
X
X case STARTCHAR : strcpy(p,STARTSTR);
X p+=strlen(STARTSTR);
X break;
X
X default : *(p++)=*line;
X }
X
X line++;
X }
X *p='\0';
X tocon(output);
X}
X
X
Xchar *skrunch(line)
X char *line;
X{
X char skbuf[LINELEN],*p;
X int spaces=0;
X
X /* first tokenizes the STARTSTR/XnSTR if in line */
X
X tokenize(line,STARTSTR,STARTCHAR);
X
X /* this is the compaction of >2 spaces */
X p=skbuf;
X while( *line )
X {
X if( *line==' ' )
X spaces++;
X else
X {
X if( spaces )
X if( spaces>2 )
X {
X *(p++)=(char)SKRUNCHAR;
X *(p++)=(char)(spaces+SKRUNOFFS);
X spaces=0;
X }
X else
X {
X *(p++)=' ';
X if( spaces>1 ) *(p++)=' ';
X spaces=0;
X }
X
X *p=*line;
X p++;
X }
X line++;
X }
X *p='\0';
X strcpy(buffer,skbuf);
X return buffer;
X}
X
X
X/* will tokenize first occurance of STR in LINE */
Xtokenize(line,str,chr)
X char *line,*str;
X int chr;
X{
X char *p,*q;
X
X if( p=mystrstr(line,str,1) )
X {
X q=p+strlen(str);
X *p=(char)chr;
X strcpy(p+1,q);
X return 1;
X }
X return 0;
X}
X
X/* stores line to memory */
Xstore(buffer)
X char *buffer;
X{
X struct mem_block *p;
X int i;
X
X i=strlen(buffer);
X chrcount+=i;
X
X if( chrcount>=BLKSIZE )
X {
X if( mem_block_ptr )
X *mem_block_ptr='\0';
X chrcount=i;
X
X if( (p=(struct mem_block *)malloc(sizeof(struct mem_block)) )==NULL)
X {
X errorstr=outofmem;
X return 2;
X }
X
X p->next=NULL;
X
X if( mem_blocks )
X cur_mem_block->next=p;
X else
X mem_blocks=p;
X cur_mem_block=p;
X
X mem_block_ptr=cur_mem_block->buffer;
X }
X
X strcpy(mem_block_ptr,buffer);
X mem_block_ptr+=i;
X
X return 0;
X}
X
Xwrite_bufblks(BPTR fd)
X{
X struct mem_block *p;
X
X p=mem_blocks;
X while(p)
X {
X if( fputstr(p->buffer,fd) )
X return 1;
X p=p->next;
X }
X
X return 0;
X}
X
X
Xvoid init_bufblks()
X{
X mem_block_ptr=NULL;
X chrcount=BLKSIZE+1;
X cur_mem_block=NULL;
X mem_blocks=NULL;
X}
X
Xvoid free_bufblks()
X{
X struct mem_block *p,*next;
X
X p=mem_blocks;
X while(p)
X {
X next=p->next;
X free(p);
X p=next;
X }
X}
X
X
Xvoid get_dlpath()
X{
X BPTR lock;
X
X dlpath[MAXPATHLEN]='\0';
X
X if( lock=Lock(dltemp,(long)ACCESS_READ) )
X {
X strncpy(dlpath,dltemp,MAXPATHLEN);
X UnLock(lock);
X }
X else
X strncpy(dlpath,dldisk,MAXPATHLEN);
X}
X
XBPTR opendl(mode)
X long mode;
X{
X BPTR fdl;
X
X if( (fdl=Open(dlpath,mode))==NULL)
X {
X errorstr="Can't open DiskList.";
X return 0;
X }
X return fdl;
X}
X
X
X#define MODE_APPEND 1000L
X
XBPTR opentmp(mode)
X long mode;
X{
X BPTR ftmp;
X BPTR lock;
X int seek=0;
X
X if( mode==MODE_APPEND)
X {
X if( lock=Lock(tempdl,(long)ACCESS_READ) )
X {
X UnLock(lock);
X mode=(long)MODE_OLDFILE;
X seek=1;
X }
X else
X mode=(long)MODE_NEWFILE;
X }
X
X if( (ftmp=Open(tempdl,mode))==NULL)
X {
X errorstr=" Can't open TempDL.";
X return 0;
X }
X
X if( seek )
X Seek(ftmp,0L,(long)OFFSET_END);
X
X return ftmp;
X}
X
X
Xsdir()
X{
X char *p;
X
X if( *(p=firstchar(strbuf))=='\0' )
X p=sdir_pat;
X
X if( !(ftmp=opentmp(MODE_APPEND)) )
X return 1;
X
X if( do_ls(p,ftmp,subdir) )
X {
X Close(ftmp);
X return 2;
X }
X Close(ftmp);
X return 0;
X}
X
X
X#define ls_cleanup(x) { ls_free(lock,f_info); return x; }
X
Xdo_ls(pat,fh,recur)
X char *pat;
X BPTR fh;
X int recur;
X{
X BPTR lock=NULL;
X struct FileInfoBlock *f_info;
X
X char *s, *tempstr;
X int slen, isadir, col, patchg=0, firstrun=1;
X char *spaces1, *spaces2;
X struct disk *nextdir;
X char basename[80], tempname[80];
X
X
X /* strings of 18 & 36 spaces for formatting output */
X /* 012345678901234567 */
X spaces1=" ";
X /* 0123456789012345678901234567890123456 */
X spaces2=" ";
X
X INIT_DISKNAMES;
X nextdir=NULL;
X
X strcpy(tempname,"/");
X tempstr=tempname+1;
X
X if((f_info=(struct FileInfoBlock *)
X AllocMem((long)sizeof(struct FileInfoBlock),0L))==0)
X {
X errorstr=outofmem;
X FREE_DISKNAMES;
X return 1;
X }
X
X do
X {
X if( firstdisk )
X {
X while( nextdir && *(nextdir->name)=='/' )
X {
X strncpy(basename,(nextdir->name)+1,78);
X strncpy(basename+strlen(basename),"/",2);
X nextdir=nextdir->next;
X if( !nextdir )
X ls_cleanup(0)
X }
X strncpy(tempname+1,basename,78);
X slen=strlen(tempname);
X strncpy(tempname+slen,nextdir->name,79-slen);
X if( storename(tempname) )
X ls_cleanup(1);
X pat=tempname+1;
X }
X
X do
X {
X if( firstrun )
X {
X if(patchg==1)
X {
X patchg=2;
X strncpy(tempstr,f_info->fib_FileName,78);
X slen=strlen(tempstr);
X tempstr[slen]=':';
X strncpy(tempstr+slen+1,s+4,78-slen);
X pat=tempstr;
X }
X else if( strchr(pat,':')<strchr(pat,'\0')-1 )
X {
X patchg=2;
X if( !(strncmp(pat,"df0:",4) && strncmp(pat,"df1:",4)) )
X {
X patchg=1;
X strncpy(tempstr,pat,4);
X *(tempstr+4)='\0';
X s=pat;
X pat=tempstr;
X }
X }
X }
X
X if((lock=Lock(pat,(long)ACCESS_READ))==0)
X ls_cleanup(2)
X
X if((Examine(lock,f_info))==0)
X ls_cleanup(3)
X }
X while( patchg==1 );
X firstrun=0;
X
X if( fputstr(STARTSTR,fh) )
X ls_cleanup(4)
X if( firstdisk )
X {
X fputstr(tempname+1,fh);
X fputstr ("\n",fh);
X }
X else
X {
X if( patchg )
X {
X patchg=0;
X if( fputstr(pat,fh) )
X ls_cleanup(5)
X fputstr ("\n",fh);
X strncpy(basename,pat,79L);
X slen=strlen(basename);
X basename[slen++]='/';
X basename[slen]='\0';
X
X }
X else
X {
X if( fputstr(f_info->fib_FileName,fh) )
X ls_cleanup(6)
X fputstr (":\n",fh);
X strncpy(basename,f_info->fib_FileName,78);
X slen=strlen(basename);
X basename[slen++]=':';
X basename[slen]='\0';
X }
X }
X col=0;
X
X while( (ExNext(lock,f_info))!=0)
X {
X s=f_info->fib_FileName;
X slen=strlen(s);
X isadir= (f_info->fib_DirEntryType>0);
X
X if((col == 3) && slen >18) {
X fputstr("\n",fh);
X col = 0;
X }
X
X if (isadir)
X fputstr ("\033[33m ",fh);
X else
X fputstr (" ",fh);
X
X if (slen >18) {
X if( fputstr(s,fh) )
X ls_cleanup(7)
X col += 2;
X if( fputstr(spaces2+slen,fh) )
X ls_cleanup(8)
X }
X else {
X if( fputstr(s,fh) )
X ls_cleanup(9)
X if( fputstr(spaces1+slen,fh) )
X ls_cleanup(10)
X col++;
X }
X
X if( isadir && recur )
X if(storename(s))
X ls_cleanup(1);
X
X if (isadir)
X fputstr("\033[0m",fh);
X
X if (col > 3) {
X fputstr("\n",fh);
X col = 0;
X }
X
X }
X fputstr("\n",fh);
X if( col )
X fputstr("\n",fh);
X
X UnLock(lock);
X lock=NULL;
X
X if( nextdir )
X nextdir=nextdir->next;
X else
X nextdir=firstdisk;
X }
X while( nextdir );
X
X ls_free(lock,f_info);
X return 0;
X}
X
Xvoid ls_free(lock,f_info)
X BPTR lock;
X struct FileInfoBlock *f_info;
X
X{
X if( lock )
X UnLock(lock);
X FreeMem(f_info,(long)sizeof(struct FileInfoBlock));
X FREE_DISKNAMES;
X}
X
X
Xfputstr(str,fh)
X char *str;
X BPTR fh;
X{
X long len;
X len=(long)strlen(str);
X if( Write(fh,str,len)==len)
X return 0;
X return 1;
X}
X
X
Xsavedl()
X{
X if( update() )
X return 1;
X
X if( strcmp(dlpath,dldisk) )
X {
X if( copy(dlpath,dldisk) )
X return 2;
X DeleteFile(dlpath);
X strncpy(dlpath,dldisk,MAXPATHLEN);
X DeleteFile(tempdl);
X }
X return 0;
X}
X
Xloaddl()
X{
X if( strcmp(dltemp,dlpath) )
X if( copy(dlpath,dltemp) )
X return 1;
X strncpy(dlpath,dltemp,MAXPATHLEN);
X return 0;
X}
X
Xnewdl()
X{
X BPTR fh;
X
X if( fh=Open(dlpath,(long)MODE_NEWFILE) )
X {
X Close(fh);
X return 0;
X }
X return 1;
X}
X
Xcopy(src,dest)
X char *src,*dest;
X{
X BPTR sfh,dfh;
X char *buffer;
X int len;
X
X if((sfh=Open(src,(long)MODE_OLDFILE))==0)
X return 1;
X
X if((dfh=Open(dest,(long)MODE_NEWFILE))==0)
X {
X Close(sfh);
X return 2;
X }
X if( (buffer=(char *)AllocMem(CP_BUFF,0L))==0)
X {
X Close(sfh);
X Close(dfh);
X errorstr=outofmem;
X return 3;
X }
X
X do
X {
X len=Read(sfh,buffer,CP_BUFF);
X Write(dfh,buffer,(long)len);
X }
X while( len!=0 );
X
X FreeMem(buffer,CP_BUFF);
X
X Close(sfh);
X Close(dfh);
X return 0;
X}
X
Xchar *firstchar(s)
X char *s;
X{
X while(*s==' ')
X s++;
X return s;
X}
X
X/* OK, this is not quite a true strstr() with case switch.
X The sub string must be in upper case if kase=0 (?!sorry) */
Xchar *mystrstr(string,sub,kase)
X char *string,*sub;
X int kase;
X{
X int length;
X char copstr[LINELEN], *str;
X
X /* string copied so it will not be converted to upper case */
X strcpy(copstr,string);
X str=copstr;
X
X length=strlen(sub);
X
X if( kase )
X str=strchr(str,*sub);
X else
X str=strchr(strtoupper(str),*sub);
X
X while( str )
X {
X if( strncmp(str,sub,length) )
X str++;
X else
X return string+(str-copstr);
X
X str=strchr(str,*sub);
X }
X return NULL;
X}
X
Xchar *strtoupper(s)
X char *s;
X{
X register char *p = s;
X
X while(*p)
X {
X *p = toupper(*p);
X p++;
X }
X return(s);
X}
X
X
X/* Following lifted from ...*/
X
X/* misc.c
X * Misc. subroutines that like to live together...
X *
X * Phillip Lindsay (c) 1987 Commodore-Amiga - This code may be freely used
X * as long as the copyright notice is left intact.
X */
X
X/* btoc() takes a pointer to a BSTR and converts it to a
X * C string.
X */
Xchar *btoc(bstring)
XCPTR bstring;
X{
X register UBYTE len,count,*cstring=NULL;
X
X if (bstring) {
X cstring = (UBYTE *) bstring;
X len = cstring[0];
X for(count=0;count < len;count++)
X cstring[count] = cstring[count+1];
X
X cstring[count] = '\0';
X }
X return((char *)cstring);
X}
X
X/*
X * find a dos node in the system device list
X *
X */
Xstruct DeviceNode *finddosnode(lookfor)
Xchar *lookfor;
X{
X extern struct DosLibrary *DOSBase;
X struct RootNode *rnode;
X struct DosInfo *dinfo;
X register struct DeviceNode *dnode;
X register char *bname;
X char name2[81];
X BOOL found = FALSE;
X
X rnode = (struct RootNode *) DOSBase->dl_Root; /* find root node */
X dinfo = (struct DosInfo *) BADDR(rnode->rn_Info); /* now dos info */
X
X Forbid();
X
X for(dnode = (struct DeviceNode *) BADDR(dinfo->di_DevInfo); ( dnode ) ;
X dnode = (struct DeviceNode *) BADDR(dnode->dn_Next))
X {
X bname = (char *) BADDR(dnode->dn_Name);
X memmove(name2, bname, (ULONG)( bname[0] + 1 ) );
X
X if ( !( strcmp( lookfor, strtoupper(btoc(name2)) ) ) ) {
X found = TRUE;
X break;
X }
X
X }
X
X Permit();
X
X return dnode; /* NULL if not found */
X}
X
X/* end of misc.c */
X
END_OF_FILE
if test 22393 -ne `wc -c <'fd3src/fd3.c'`; then
echo shar: \"'fd3src/fd3.c'\" unpacked with wrong size!
fi
# end of 'fd3src/fd3.c'
fi
echo shar: End of archive 3 \(of 3\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 3 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.misc.